//
//  EMMSearchViewController.m
//  EMMApp
//
//  Created by Mac on 16/5/5.
//  Copyright © 2016年 YiXun. All rights reserved.
//

#import "EMMSearchViewController.h"
#import "TouristsCell.h"
#import "MultiFunctionTableView.h"
#import "TouristsModel.h"
#import <MessageUI/MessageUI.h>
#import "FuzzySearchView.h"
#import "GetSearchListApi.h"
#import "GetConsultantListApi.h"
#import "DistributionConsultantApi.h"
#import "FollowUpViewController.h"
#import "EMMTouristsCell.h"
#import "EMMTouristsNewCell.h"
#import "FirstTouchController.h"
#import "TouristsDetailWebViewController.h"
@interface EMMSearchViewController ()<UITableViewDataSource,
                                        UITableViewDelegate,
                                        UITextFieldDelegate,
                                        MultiFunctionTableViewDelegate,
                                        MFMessageComposeViewControllerDelegate> {
    UITableViewRowAction *deleteRowAction;
    UITableViewRowAction *moreRowAction;
    UITableViewRowAction *sanRowAction;
    UITableViewRowAction *OK;
    UIView *footerView;
}

@property (nonatomic, strong) UILabel *cratOneLabel;

@property (nonatomic, strong) GetConsultantList *getConsultantList;

@property (nonatomic, strong) MultiFunctionTableView *touristsTableView;

@property (nonatomic, strong) UITableView *sListTabelView;

@property (nonatomic, strong) UITextField *textFiledOne;    //搜索框

@property (nonatomic, strong) UIButton *cancelBtn;         //取消按钮

@property (nonatomic, strong) NSMutableArray *dataArr;      //数据源数组

@property (nonatomic, strong) UILabel *searchLabel;
@property (nonatomic, strong) UIButton *tourbtn;


@property (nonatomic, strong) UILabel *dataLabel;

@property (nonatomic,strong) NSArray *yhArr;


@property (nonatomic, strong) NSMutableArray *zyData;
@property (nonatomic, strong) NSMutableArray *zyDataArr;
@property (nonatomic, strong) NSMutableArray *zyDataArrId;

@property (nonatomic, copy) NSString *inputText;
@property (nonatomic, weak) FuzzySearchView *searchView;

@end

@implementation EMMSearchViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    _zyData = [[NSMutableArray alloc] init];
    _zyDataArr = [[NSMutableArray alloc] init];
    [self creatNavigationController];
    _dataArr = [[NSMutableArray alloc] init];
    self.view.backgroundColor = [UIColor whiteColor];
    _touristsTableView = [[MultiFunctionTableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    _touristsTableView.backgroundColor = [UIColor colorWithRed:235/255.0 green:235/255.0 blue:235/255.0 alpha:1];
    _touristsTableView.delegate = self;
    _touristsTableView.dataSource = self;
    _touristsTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    _touristsTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _touristsTableView.hidden = YES;
    _touristsTableView.showsVerticalScrollIndicator = NO;
    
    self.touristsTableView.multiTableDelegate = self;
    [self.view addSubview:_touristsTableView];
    
    _dataLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 150, EMM_WIDTH, 20)];
    _dataLabel.text = @"没有找到你要的客户，请重新查询";
    _dataLabel.textAlignment = NSTextAlignmentCenter;
    _dataLabel.hidden = YES;
    [self.view addSubview:_dataLabel];
    
    [self searchShowUI];
    
    NSUserDefaults *userdf = [NSUserDefaults standardUserDefaults];
//    NSString *roleType = [userdf objectForKey:@"roleType"];
//    if ([NSString isStringEmpty2:roleType] == NO) {
//        if ([roleType isEqualToString:@"1"]) {
//            _yhArr = [NSArray arrayWithObjects:@"打电话",@"发短信",@"写跟进", nil];
//            
//        }else {
//            _yhArr = [NSArray arrayWithObjects:@"打电话",@"发短信",@"写跟进",@"分配", nil];
//        }
//    }
    NSString *isAddCustomer = [userdf objectForKey:@"isAddCustomer"];//客户菜单权限下按钮权限：客户新增
    NSString *isDistributionCustomer = [userdf objectForKey:@"isDistributionCustomer"];//客户菜单权限下按钮权限：客户分配
    if ([isAddCustomer isEqualToString:@"1"] && [isDistributionCustomer isEqualToString:@"1"]) {
        _yhArr = [NSArray arrayWithObjects:@"打电话",@"首触",@"写跟进",@"分配", nil];
        [self postGetConsultantListApi];

    }else if ([isAddCustomer isEqualToString:@"0"] && [isDistributionCustomer isEqualToString:@"1"]) {
        _yhArr = [NSArray arrayWithObjects:@"打电话",@"首触",@"写跟进",@"分配", nil];
        [self postGetConsultantListApi];

    }else if ([isAddCustomer isEqualToString:@"1"] && [isDistributionCustomer isEqualToString:@"0"]) {
        _yhArr = [NSArray arrayWithObjects:@"打电话",@"首触",@"写跟进", nil];
    }else if ([isAddCustomer isEqualToString:@"0"] && [isDistributionCustomer isEqualToString:@"0"]) {
        _yhArr = [NSArray arrayWithObjects:@"打电话",@"首触",@"写跟进", nil];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
}

#pragma mark - 导航

- (void)creatNavigationController {
    [self updateNavBar];
    self.navigationItem.title = @"搜索";
    [self configLeftBtn];
    [self creatSearch];
}


#pragma mark -

- (void)creatSearch
{
    
    FuzzySearchView *searchView = [[FuzzySearchView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 30) placeholderText:@"请输入客户姓名或手机号码" inputTextDidChange:^(NSString *text) {
           self.inputText = text;
    } cancelClick:^{
        
        if (self.inputText.length > 0) {
            _sListTabelView.hidden = YES;
            [self postGetSearchListApiSearchContent:self.inputText];
        }else {
            _sListTabelView.hidden = NO;
            _dataLabel.hidden = YES;
            _touristsTableView.hidden = YES;
        }
        
        [self cancelBtnClick];
    }];
    [searchView returnKeyboardClick:^(NSString *searchtext) {
        if (searchtext.length > 0) {
            _sListTabelView.hidden = YES;
            [self postGetSearchListApiSearchContent:searchtext];
            self.inputText = searchtext;
        }else {
            _sListTabelView.hidden = NO;
            _dataLabel.hidden = YES;
            _touristsTableView.hidden = YES;
        }
        
    }];
    self.searchView = searchView;
    searchView.hiddenCancel = NO;
    self.navigationItem.titleView = searchView;
    
//    UIView *sView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, EMM_WIDTH, 60)];
//    sView.backgroundColor = [UIColor whiteColor];
//    [self.view addSubview:sView];
//    
//    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 59, EMM_WIDTH, 1)];
//    view.backgroundColor = [UIColor colorWithRed:235/255.0 green:235/255.0 blue:235/255.0 alpha:1];
//    [sView addSubview:view];
//    
//    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
//    CGColorRef colorref = CGColorCreate(colorSpace, (CGFloat[]){0.1,0,0,0.1});
//    
//    UIView *textView = [[UIView alloc] initWithFrame:CGRectMake(10, 10, EMM_WIDTH-95, 40)];
//    [textView.layer setMasksToBounds:YES];
//    [textView.layer setCornerRadius:5.0]; //设置矩形四个圆角半径
//    [textView.layer setBorderWidth:1.0]; //边框宽度
//    [textView.layer setBorderColor:colorref];
//    [sView addSubview:textView];
//    
//    _textFiledOne = [[UITextField alloc] initWithFrame:CGRectMake(15, 0, textView.frame.size.width-15, 40)];
//    _textFiledOne.placeholder = @"请输入客户姓名或手机号";
//    _textFiledOne.delegate = self;
//    _textFiledOne.backgroundColor = [UIColor whiteColor];
//    _textFiledOne.returnKeyType = UIReturnKeySearch;
//    _textFiledOne.delegate = self;
//      [_textFiledOne addTarget:self action:@selector(textFiledOneClik:) forControlEvents:UIControlEventEditingChanged];
//    [textView addSubview:_textFiledOne];
//    
//    _cancelBtn = [UIButton buttonWithType:UIButtonTypeSystem];
//    _cancelBtn.frame = CGRectMake(EMM_WIDTH-80, 10, 70, 40);
//    [_cancelBtn setTitle:@"搜索" forState:UIControlStateNormal];
//    [_cancelBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//    [_cancelBtn.layer setMasksToBounds:YES];
//    [_cancelBtn.layer setCornerRadius:5.0];
//    _cancelBtn.backgroundColor = [UIColor colorFromHexCode:@"#f87242"];
//    [_cancelBtn addTarget:self action:@selector(cancelBtnClick:) forControlEvents:UIControlEventTouchUpInside];
//    [sView addSubview:_cancelBtn];
    
}

////////////////////////////////////////////////////////////////////////////////////////////////////

#pragma mark -搜索记录

- (void)searchShowUI
{
    NSArray *arr = [[NSUserDefaults standardUserDefaults] objectForKey:@"search"];
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    for (NSString *str in arr) {
        [dict setObject:str forKey:str];
    }
    if ([dict allKeys].count >10) {
        _sListTabelView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, EMM_WIDTH, 10*40+80) style:UITableViewStylePlain];
    }else {
        if ([dict allKeys].count > 0) {
            _sListTabelView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, EMM_WIDTH, [dict allKeys].count*40+80) style:UITableViewStylePlain];
        }else {
            _sListTabelView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, EMM_WIDTH, 40+80) style:UITableViewStylePlain];
        }
    }
    
    _sListTabelView.backgroundColor = [UIColor whiteColor];
    _sListTabelView.delegate = self;
    _sListTabelView.dataSource = self;
    _sListTabelView.separatorStyle = UITableViewCellSeparatorStyleNone;
//    _sListTabelView.scrollEnabled = NO;
    _sListTabelView.showsVerticalScrollIndicator = NO;
    [self.view addSubview:_sListTabelView];
    
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, EMM_WIDTH, 40)];
    UILabel *l = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, EMM_WIDTH-20, 40)];
    l.text = @"搜索历史:";
    l.textColor = [UIColor colorFromHexCode:@"#999999"];
    [headerView addSubview:l];
    UIImageView *image1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 39, EMM_WIDTH, 1)];
    image1.backgroundColor = [UIColor colorFromHexCode:@"#999999"];
    [headerView addSubview:image1];
    _sListTabelView.tableHeaderView = headerView;
    
    footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, EMM_WIDTH, 40)];
    UILabel *l1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, EMM_WIDTH, 40)];
    l1.text = @"清空历史记录";
    l1.textAlignment = NSTextAlignmentCenter;
    l1.textColor = [UIColor colorFromHexCode:@"#999999"];
    [footerView addSubview:l1];
    UIImageView *image2 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 39, EMM_WIDTH, 1)];
    image2.backgroundColor = [UIColor colorFromHexCode:@"#999999"];
    [headerView addSubview:image2];
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
    btn.frame = CGRectMake(0, 0, EMM_WIDTH, 40);
    [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [footerView addSubview:btn];
    
    if (arr.count > 0) {
        footerView.hidden = NO;
        _sListTabelView.tableFooterView = footerView;
    }else {
        footerView.hidden = YES;
    }
}

#pragma mark  - 点击搜索按钮
- (void)cancelBtnClick
{
    if (self.inputText.length == 0) {
        return;
    }
    NSMutableArray *arr = [[NSMutableArray alloc] init];
    if ([[NSUserDefaults standardUserDefaults] arrayForKey:@"search"].count > 0) {
        arr = [[[NSUserDefaults standardUserDefaults] arrayForKey:@"search"] mutableCopy];
    }
    [arr addObject:self.inputText];
    [[NSUserDefaults standardUserDefaults] setObject:arr forKey:@"search"];
    [[NSUserDefaults standardUserDefaults] synchronize];
    [_sListTabelView reloadData];
    
    NSArray *arr1 = [[NSUserDefaults standardUserDefaults] objectForKey:@"search"];
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    for (NSString *str in arr1) {
        [dict setObject:str forKey:str];
    }
    [[NSUserDefaults standardUserDefaults] setObject:[dict allKeys] forKey:@"search"];
    [[NSUserDefaults standardUserDefaults] synchronize];
    if ([dict allKeys].count >10) {
        _sListTabelView.frame = CGRectMake(0, 0, self.view.frame.size.width, 10*40+80);
    }else {
        if ([dict allKeys].count > 0) {
            _sListTabelView.frame = CGRectMake(0, 0, self.view.frame.size.width, [dict allKeys].count*40+80);
        }else {
            _sListTabelView.frame = CGRectMake(0, 0, self.view.frame.size.width, 40+80);
        }
    }
    [self postGetSearchListApiSearchContent:self.inputText];
}

#pragma mark - 搜索框 值改变触发事件
- (void)textFiledOneClik:(UITextField *)textFiled
{
    if (textFiled.text.length > 0) {
        _sListTabelView.hidden = YES;
//        NSMutableArray *arr = [[NSMutableArray alloc] init];
//        if ([[NSUserDefaults standardUserDefaults] arrayForKey:@"search"].count > 0) {
//            arr = [[[NSUserDefaults standardUserDefaults] arrayForKey:@"search"] mutableCopy];
//        }
//        [arr addObject:_textFiledOne.text];
//        [[NSUserDefaults standardUserDefaults] setObject:arr forKey:@"search"];
//        [[NSUserDefaults standardUserDefaults] synchronize];
//        [_sListTabelView reloadData];
//        
//        NSArray *arr1 = [[NSUserDefaults standardUserDefaults] objectForKey:@"search"];
//        NSMutableDictionary *dict = [NSMutableDictionary dictionary];
//        for (NSString *str in arr1) {
//            [dict setObject:str forKey:str];
//        }
//        [[NSUserDefaults standardUserDefaults] setObject:[dict allKeys] forKey:@"search"];
//        [[NSUserDefaults standardUserDefaults] synchronize];
        [self postGetSearchListApiSearchContent:self.inputText];
    }else {
        _sListTabelView.hidden = NO;
        _dataLabel.hidden = YES;
        _touristsTableView.hidden = YES;
    }
}

////////////////////////////////////////////////////////////////////////////////////////////////////

#pragma mark - 清除搜索记录按钮响应事件
- (void)btnClick:(UIButton *)btn
{
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"删除搜索历史记录" preferredStyle:UIAlertControllerStyleAlert];
    [alertController addAction:[UIAlertAction actionWithTitle:@"确定"style:UIAlertActionStyleDefault handler:^(UIAlertAction*action) {
        [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"search"];
        [[NSUserDefaults standardUserDefaults] synchronize];
        NSArray *arr = [[NSUserDefaults standardUserDefaults] objectForKey:@"search"];
        if (arr.count == 0) {
            footerView.hidden = YES;
        }else {
            footerView.hidden = NO;
            _sListTabelView.tableFooterView = footerView;
        }
        [_sListTabelView reloadData];
        _sListTabelView.frame = CGRectMake(0, 0, EMM_WIDTH, 40+80);
    }]];
    [alertController addAction: [UIAlertAction actionWithTitle:@"取消"style:UIAlertActionStyleCancel handler:^(UIAlertAction*action) {
    }]];
    [self presentViewController:alertController animated:YES completion:nil];
}

////////////////////////////////////////////////////////////////////////////////////////////////////

#pragma mark - UITableViewDataSource 与 UITableViewDelegate

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (tableView == _sListTabelView) {
        NSArray *arr = [[NSUserDefaults standardUserDefaults] objectForKey:@"search"];
        NSMutableDictionary *dict = [NSMutableDictionary dictionary];
        for (NSString *str in arr) {
            [dict setObject:str forKey:str];
        }
        if (arr.count > 0) {
            if (arr.count >= 10) {
                return 10;
            }else {
                return [dict allKeys].count;
            }
        }else {
            return 1;
        }
        return 0;
    }else {
        return _dataArr.count;
    }
    return 0;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView == _sListTabelView) {
        return 40;
    }else {
        return 90;
    }
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView == _sListTabelView) {
        static NSString *cellID = @"cellID";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 39, self.view.frame.size.width, 1)];
        view.backgroundColor = [UIColor colorWithRed:235/255.0 green:235/255.0 blue:235/255.0 alpha:1];
        [cell addSubview:view];
        NSArray *arr = [[NSUserDefaults standardUserDefaults] objectForKey:@"search"];
        NSArray* reversedArray = [[arr reverseObjectEnumerator] allObjects];
        NSMutableDictionary *dict = [NSMutableDictionary dictionary];
        for (NSString *str in reversedArray) {
            [dict setObject:str forKey:str];
        }
        //        NSLog(@"%@", [dict allKeys]);
        _searchLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 0, EMM_WIDTH-40, 40)];
        _searchLabel.textColor = [UIColor colorFromHexCode:@"#999999"];
        [cell addSubview:_searchLabel];
        
        if (arr.count > 0) {
            cell.textLabel.text = [[dict allKeys] objectAtIndex:indexPath.row];
            _searchLabel.text = nil;
        }else {
            
            _searchLabel.text = @"当前没有搜索记录";
            _searchLabel.textAlignment = NSTextAlignmentCenter;
            cell.textLabel.text = nil;
        }
        return cell;
    }
    NSString *cellId = @"EMMTouristsNewCellId";
    EMMTouristsNewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (cell == nil) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"EMMTouristsNewCell" owner:self options:nil] lastObject];
    }
    cell.backgroundColor = [UIColor whiteColor];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (_dataArr.count > 0) {
        CustomerList *list = [_dataArr objectAtIndex:indexPath.row];
        if ([list.star isEqualToString:@"是"]) {
            cell.xjImageV.hidden = NO;
        }else {
            cell.xjImageV.hidden = YES;
        }
        
        cell.khNameLabel.text = list.customerName;
        cell.khDJLabel.text = [NSString stringWithFormat:@"(%@)",list.intentionLevel];
        cell.khZTLabel.text = list.customerStatus;
        cell.khLYLabel.text = list.customerOrigin;
        if ([NSString isStringEmpty2:list.attributionName] == NO) {
            cell.gsNameLabel.text = list.attributionName;
        }
        cell.khTimerLabel.text = list.createTime;
        
        
        CGFloat width = cell.frame.size.width * 0.4;
        NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:15],};
        CGSize textSize = [cell.khNameLabel.text boundingRectWithSize:cell.frame.size options:NSStringDrawingTruncatesLastVisibleLine attributes:attributes context:nil].size;
        if (textSize.width > width ) {
            cell.starLeadingCons.constant = width;
            cell.nameHeightCons.constant = 50;
        }else {
            cell.nameHeightCons.constant = 20;
            cell.starLeadingCons.constant = textSize.width + 10;
        }

        cell.khDJLabel.hidden = [list.dataAuthority isEqualToString:@"0"];
        cell.khZTLabel.hidden = [list.dataAuthority isEqualToString:@"0"];
        
    }
    return cell;
}

- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView == _touristsTableView) {
        NSUserDefaults *userdf = [NSUserDefaults standardUserDefaults];
//        NSString *roleType = [userdf objectForKey:@"roleType"];
        NSString *isAddCustomer = [userdf objectForKey:@"isAddCustomer"];//客户菜单权限下按钮权限：客户新增
        NSString *isDistributionCustomer = [userdf objectForKey:@"isDistributionCustomer"];//客户菜单权限下按钮权限：客户分配
        //isAddCustomer = @"0"; isDistributionCustomer = @"0";
        if ([isAddCustomer isEqualToString:@"1"] && [isDistributionCustomer isEqualToString:@"1"]) {
            deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"打电话" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
                NSLog(@"点击了打电话");
                CustomerList *list = [_dataArr objectAtIndex:indexPath.row];
//                NSString *isPhoneInformation = [userdf objectForKey:@"isPhoneInformation"];
//                if ([NSString isStringEmpty2:isPhoneInformation] == NO) {
//                    if ([isPhoneInformation isEqualToString:@"0"]) {
//                        if ([NSString isStringEmpty2:list.mobile] == NO) {
//                            [self creatinitWithGetPhone:list.mobile];
//                        }
//                    }else if ([isPhoneInformation isEqualToString:@"1"]) {
//                        [self postGetUserCallListApi:list];
//                    }
//                }else {
//                    if ([NSString isStringEmpty2:list.mobile] == NO) {
//                        [self creatinitWithGetPhone:list.mobile];
//                    }
//                }
                [self postGetUserCallListApi:list];
            }];
            
            moreRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"首触" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
                NSLog(@"点击了发短信");
                CustomerList *list = [_dataArr objectAtIndex:indexPath.row];
//                if ([NSString isStringEmpty2:list.mobile] == NO) {
//                    NSMutableArray *arr = [[NSMutableArray alloc] initWithObjects:list.mobile, nil];
                    [self creatinitWithGetNoteArr:list];
//                }
            }];
            
            sanRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"写跟进" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
                NSLog(@"点击了写跟进");
                CustomerList *list = [_dataArr objectAtIndex:indexPath.row];
                [self creatinitWithGetReadAfterWriteCustomerId:list.customerId
                                                  customerName:list.customerName
                                                          star:list.star
                                                intentionLevel:list.intentionLevel
                                                customerOrigin:list.customerOrigin
                                                customerStatus:list.customerStatus
                                                        mobile:list.mobile
                                                           sex:list.customerSex];
            }];
            
            OK = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"分配" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
                NSLog(@"点击了分配");
                if (_zyDataArr.count == 0) {
                    [self showToast:@"暂无经纪人可选"];
                    return ;
                }
                CustomerList *list = [_dataArr objectAtIndex:indexPath.row];
                ShowMenuView *menuView = [[ShowMenuView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) title:@"选项" titleNmae:@"经纪人" numLits:nil items:_zyDataArr];
                menuView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
                [[UIApplication sharedApplication].keyWindow addSubview:menuView];
                __weak ShowMenuView *weakMenuView = menuView;
                [menuView setTouchBlock:^(NSString *indet,NSString *number) {
                    NSLog(@"%@",indet);
                    if ([NSString isStringEmpty2:indet] == NO) {
                        ConsultantList *consList = [_zyData objectAtIndex:[number intValue]-1];
                        NSString *consultantId = consList.consultantUserId;
                        NSArray *arr = @[@{@"customerId":list.customerId}];
                        
                        [self postDistributionConsultantApiConsultantUserId:consultantId customerList:arr];
                    }
                    [weakMenuView removeFromSuperview];
                    
                    
                }];
            }];
            deleteRowAction.backgroundColor = [UIColor colorFromHexCode:@"#f82b49"];
            moreRowAction.backgroundColor = [UIColor colorFromHexCode:@"#ff6253"];
            sanRowAction.backgroundColor = [UIColor colorFromHexCode:@"#ff7200"];
            OK.backgroundColor = [UIColor colorFromHexCode:@"#ffb527"];
            return @[OK,sanRowAction,moreRowAction,deleteRowAction];
        }else if ([isAddCustomer isEqualToString:@"0"] && [isDistributionCustomer isEqualToString:@"1"]) {
            deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"打电话" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
                NSLog(@"点击了打电话");
                CustomerList *list = [_dataArr objectAtIndex:indexPath.row];
//                NSString *isPhoneInformation = [userdf objectForKey:@"isPhoneInformation"];
//                if ([NSString isStringEmpty2:isPhoneInformation] == NO) {
//                    if ([isPhoneInformation isEqualToString:@"0"]) {
//                        if ([NSString isStringEmpty2:list.mobile] == NO) {
//                            [self creatinitWithGetPhone:list.mobile];
//                        }
//                    }else if ([isPhoneInformation isEqualToString:@"1"]) {
//                        [self postGetUserCallListApi:list];
//                    }
//                }else {
//                    if ([NSString isStringEmpty2:list.mobile] == NO) {
//                        [self creatinitWithGetPhone:list.mobile];
//                    }
//                }
                [self postGetUserCallListApi:list];
            }];
            
            moreRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"首触" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
                NSLog(@"点击了发短信");
                CustomerList *list = [_dataArr objectAtIndex:indexPath.row];
//                if ([NSString isStringEmpty2:list.mobile] == NO) {
//                    NSMutableArray *arr = [[NSMutableArray alloc] initWithObjects:list.mobile, nil];
                    [self creatinitWithGetNoteArr:list];
//                }
            }];
            
            sanRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"写跟进" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
                NSLog(@"点击了写跟进");
                CustomerList *list = [_dataArr objectAtIndex:indexPath.row];
                [self creatinitWithGetReadAfterWriteCustomerId:list.customerId
                                                  customerName:list.customerName
                                                          star:list.star
                                                intentionLevel:list.intentionLevel
                                                customerOrigin:list.customerOrigin
                                                customerStatus:list.customerStatus
                                                        mobile:list.mobile
                                                           sex:list.customerSex];
            }];
            
            OK = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"分配" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
                NSLog(@"点击了分配");
                if (_zyDataArr.count == 0) {
                    [self showToast:@"暂无经纪人可选"];
                    return ;
                }
                CustomerList *list = [_dataArr objectAtIndex:indexPath.row];
                ShowMenuView *menuView = [[ShowMenuView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) title:@"选项" titleNmae:@"经纪人" numLits:nil items:_zyDataArr];
                menuView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
                [[UIApplication sharedApplication].keyWindow addSubview:menuView];
                __weak ShowMenuView *weakMenuView = menuView;
                [menuView setTouchBlock:^(NSString *indet,NSString *number) {
                    NSLog(@"%@",indet);
                    if ([NSString isStringEmpty2:indet] == NO) {
                        ConsultantList *consList = [_zyData objectAtIndex:[number intValue]-1];
                        NSString *consultantId = consList.consultantUserId;
                        NSArray *arr = @[@{@"customerId":list.customerId}];
                        
                        [self postDistributionConsultantApiConsultantUserId:consultantId customerList:arr];
                        
                    }
                    [weakMenuView removeFromSuperview];
                    
                    
                }];
            }];
            deleteRowAction.backgroundColor = [UIColor colorFromHexCode:@"#f82b49"];
            moreRowAction.backgroundColor = [UIColor colorFromHexCode:@"#ff6253"];
            sanRowAction.backgroundColor = [UIColor colorFromHexCode:@"#ff7200"];
            OK.backgroundColor = [UIColor colorFromHexCode:@"#ffb527"];
            return @[OK,sanRowAction,moreRowAction,deleteRowAction];
        }else if ([isAddCustomer isEqualToString:@"1"] && [isDistributionCustomer isEqualToString:@"0"]) {
            deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"打电话" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
                NSLog(@"点击了打电话");
                CustomerList *list = [_dataArr objectAtIndex:indexPath.row];
//                NSString *isPhoneInformation = [userdf objectForKey:@"isPhoneInformation"];
//                if ([NSString isStringEmpty2:isPhoneInformation] == NO) {
//                    if ([isPhoneInformation isEqualToString:@"0"]) {
//                        if ([NSString isStringEmpty2:list.mobile] == NO) {
//                            [self creatinitWithGetPhone:list.mobile];
//                        }
//                    }else if ([isPhoneInformation isEqualToString:@"1"]) {
//                        [self postGetUserCallListApi:list];
//                    }
//                }else {
//                    if ([NSString isStringEmpty2:list.mobile] == NO) {
//                        [self creatinitWithGetPhone:list.mobile];
//                    }
//                }
                [self postGetUserCallListApi:list];
            }];
            moreRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"首触" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
                NSLog(@"点击了发短信");
                CustomerList *list = [_dataArr objectAtIndex:indexPath.row];
//                if ([NSString isStringEmpty2:list.mobile] == NO) {
//                    NSMutableArray *arr = [[NSMutableArray alloc] initWithObjects:list.mobile, nil];
                    [self creatinitWithGetNoteArr:list];
//                }
            }];
            
            sanRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"写跟进" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
                NSLog(@"点击了写跟进");
                CustomerList *list = [_dataArr objectAtIndex:indexPath.row];
                [self creatinitWithGetReadAfterWriteCustomerId:list.customerId
                                                  customerName:list.customerName
                                                          star:list.star
                                                intentionLevel:list.intentionLevel
                                                customerOrigin:list.customerOrigin
                                                customerStatus:list.customerStatus
                                                        mobile:list.mobile
                                                           sex:list.customerSex];
            }];
            deleteRowAction.backgroundColor = [UIColor colorFromHexCode:@"#f82b49"];
            moreRowAction.backgroundColor = [UIColor colorFromHexCode:@"#ff6253"];
            sanRowAction.backgroundColor = [UIColor colorFromHexCode:@"#ff7200"];
            return @[sanRowAction,moreRowAction,deleteRowAction];
        }else if ([isAddCustomer isEqualToString:@"0"] && [isDistributionCustomer isEqualToString:@"0"]) {
            deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"打电话" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
                NSLog(@"点击了打电话");
                CustomerList *list = [_dataArr objectAtIndex:indexPath.row];
//                NSString *isPhoneInformation = [userdf objectForKey:@"isPhoneInformation"];
//                if ([NSString isStringEmpty2:isPhoneInformation] == NO) {
//                    if ([isPhoneInformation isEqualToString:@"0"]) {
//                        if ([NSString isStringEmpty2:list.mobile] == NO) {
//                            [self creatinitWithGetPhone:list.mobile];
//                        }
//                    }else if ([isPhoneInformation isEqualToString:@"1"]) {
//                        [self postGetUserCallListApi:list];
//                    }
//                }else {
//                    if ([NSString isStringEmpty2:list.mobile] == NO) {
//                        [self creatinitWithGetPhone:list.mobile];
//                    }
//                }
                [self postGetUserCallListApi:list];
            }];
            moreRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"首触" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
                NSLog(@"点击了发短信");
                CustomerList *list = [_dataArr objectAtIndex:indexPath.row];
//                if ([NSString isStringEmpty2:list.mobile] == NO) {
//                    NSMutableArray *arr = [[NSMutableArray alloc] initWithObjects:list.mobile, nil];
                    [self creatinitWithGetNoteArr:list];
//                }
            }];
            
            sanRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"写跟进" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
                NSLog(@"点击了写跟进");
                CustomerList *list = [_dataArr objectAtIndex:indexPath.row];
                [self creatinitWithGetReadAfterWriteCustomerId:list.customerId
                                                  customerName:list.customerName
                                                          star:list.star
                                                intentionLevel:list.intentionLevel
                                                customerOrigin:list.customerOrigin
                                                customerStatus:list.customerStatus
                                                        mobile:list.mobile
                                                           sex:list.customerSex];
            }];
            deleteRowAction.backgroundColor = [UIColor colorFromHexCode:@"#f82b49"];
            moreRowAction.backgroundColor = [UIColor colorFromHexCode:@"#ff6253"];
            sanRowAction.backgroundColor = [UIColor colorFromHexCode:@"#ff7200"];
            return @[sanRowAction,moreRowAction,deleteRowAction];
        }
    }else if (tableView == _sListTabelView) {
        return @[];
    }
    return nil;
}

#pragma mark - 打电话
- (void)creatinitWithGetPhone:(NSString *)phonString {
    NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@",phonString];
    UIWebView * callWebview = [[UIWebView alloc] init];
    [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
    [self.view addSubview:callWebview];
    NSLog(@"1");
}
#pragma mark - 发短信 更改为首触入口
- (void)creatinitWithGetNoteArr:(CustomerList *)userModel {
    
    FirstTouchController *vc = [[FirstTouchController alloc]init];
    vc.hidesBottomBarWhenPushed = YES;
    vc.userModel = userModel;
    [self.navigationController pushViewController:vc animated:YES];
    
//    if( [MFMessageComposeViewController canSendText] ){
//        MFMessageComposeViewController * controller = [[MFMessageComposeViewController alloc]init];
//        controller.recipients = dxArr;
//
//        controller.messageComposeDelegate = self;
//        [self presentViewController:controller animated:YES completion:^{
//            
//        }];
//        [[[[controller viewControllers] lastObject] navigationItem] setTitle:nil];//修改短信界面标题
//    }else{
//        [self alertWithTitle:@"提示信息" msg:@"设备没有短信功能"];
//    }
}
#pragma mark - MFMessageComposeViewControllerDelegate发短信协议代理方法调用
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {
    [controller dismissViewControllerAnimated:NO completion:^{
    }];
    switch ( result ) {
        case MessageComposeResultCancelled:
            [self alertWithTitle:@"提示信息" msg:@"发送取消"];
            break;
        case MessageComposeResultFailed:// send failed
            [self alertWithTitle:@"提示信息" msg:@"发送失败"];
            break;
        case MessageComposeResultSent:
            [self alertWithTitle:@"提示信息" msg:@"发送成功"];
            break;
        default:
            break;
    }
}
#pragma mark - 写跟进
- (void)creatinitWithGetReadAfterWriteCustomerId:(NSString *)customerId
                                    customerName:(NSString *)customerName
                                            star:(NSString *)star
                                  intentionLevel:(NSString *)intentionLevel
                                  customerOrigin:(NSString *)customerOrigin
                                  customerStatus:(NSString *)customerStatus
                                          mobile:(NSString *)mobile
                                             sex:(NSString *)sex{
    FollowUpViewController *fvc = [[FollowUpViewController alloc] init];
    fvc.hidesBottomBarWhenPushed = YES;
    fvc.customerId = customerId;
    [self.navigationController pushViewController:fvc animated:YES];
}


- (void)postDistributionConsultantApiConsultantUserId:(NSString *)consultantUserId customerList:(NSArray *)customerList {
    
    DistributionConsultantApi *api = [[DistributionConsultantApi alloc] initWithConsultantUserId:consultantUserId customerList:customerList];
    [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        DistributionConsultantApi *result = (DistributionConsultantApi *)request;
        if (result.isSuccess) {
            DistributionConsultant *get = result.resultData;
            [self showToast:@"分配成功"];
        } else {
            [self showToast:result.resultData.errorMsg];
        }
        [self hideHud];
    } failure:^(YTKBaseRequest *request) {
        [self showToast:@"连接服务器失败，请检查网络！"];
        [self hideHud];
    }];
}

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    if (tableView == _touristsTableView)  {
        CustomerList *list = [_dataArr objectAtIndex:indexPath.row];
        return [list.dataAuthority isEqualToString:@"1"];
    }else {
        return NO;
    }

}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (tableView == _touristsTableView) {
          CustomerList *list = [_dataArr objectAtIndex:indexPath.row];
        if ([list.dataAuthority isEqualToString:@"0"]) {
            [self showToast:@"您没有查看权限"];
            return;
        }
        TouristsDetailWebViewController *tvc = [[TouristsDetailWebViewController alloc] init];
        tvc.hidesBottomBarWhenPushed = YES;
        tvc.customerId = list.customerId;
        tvc.isNot = NO;
        [self.navigationController pushViewController:tvc animated:YES];
    } else {
        NSArray *arr = [[NSUserDefaults standardUserDefaults] objectForKey:@"search"];
        NSArray* reversedArray = [[arr reverseObjectEnumerator] allObjects];
        NSMutableDictionary *dict = [NSMutableDictionary dictionary];
        for (NSString *str in reversedArray) {
            [dict setObject:str forKey:str];
        }
        NSString *str = @"";
        if (dict.allKeys.count > 0) {
            str = [[dict allKeys] objectAtIndex:indexPath.row];
        } else {
            return;
        }
        self.searchView.oldSearchKey = str;
        _sListTabelView.hidden = YES;
        [self postGetSearchListApiSearchContent:str];

    }
}


////////////////////////////////////////////////////////////////////////////////////////////////////
-(void)textFieldDidEndEditing:(UITextField *)textField {
    NSArray *arr = [[NSUserDefaults standardUserDefaults] objectForKey:@"search"];
    if (arr.count == 0) {
        footerView.hidden = YES;
    }else {
        footerView.hidden = NO;
        _sListTabelView.tableFooterView = footerView;
    }
}
#pragma mark - UITextFieldDelegate

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    NSLog(@"搜索");
    
    [self postGetSearchListApiSearchContent:self.inputText];
    [textField resignFirstResponder];
    return YES;
}

- (void)postGetSearchListApiSearchContent:(NSString *)searchContent {
    if (searchContent.length == 0) {
        [self showToast:@"搜索内容不能为空"];
        return;
    }
    
    [_dataArr removeAllObjects];
    GetSearchListApi *api = [[GetSearchListApi alloc] initWithSearchContent:searchContent cusType:self.tpye];
    [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        GetSearchListApi *result = (GetSearchListApi *)request;
        if (result.isSuccess) {
            [_dataArr removeAllObjects];
            GetSearchList *get = result.resultData;
            for (CustomerList *list in get.customerList) {
                [_dataArr addObject:list];
            }
            if (_dataArr.count > 0) {
                _touristsTableView.hidden = NO;
                _dataLabel.hidden = YES;
                _sListTabelView.hidden = YES;
            }else {
                _touristsTableView.hidden = YES;
                _dataLabel.hidden = NO;
//                [self showToast:@"没有找到你要的客户，请重新查询"];
            }
            [_touristsTableView reloadData];
        } else {
            NSUserDefaults *userdf = [NSUserDefaults standardUserDefaults];
            NSString *projectCode = [userdf objectForKey:@"projectCode"];
            if ([NSString isStringEmpty2:projectCode] == NO) {
                [self showToast:result.resultData.errorMsg];
            }
            
            /*
             提示语：账号权限发生变动，请重新登录
             code随机18位唯一码：108E65843mYuwqb01X
             //YUplf0wyU5vPVssLSG 对应的异地登录退出登录
             */
            if ([result.resultData.errorCode isEqualToString:@"YUplf0wyU5vPVssLSG"] || [result.resultData.errorCode isEqualToString:@"108E65843mYuwqb01X"]) {
                NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
                NSDictionary *dictionary = [defs dictionaryRepresentation];
                for(NSString *key in [dictionary allKeys]){
                    if ([key isEqualToString:@"DeviceToken123"] ||
                        [key isEqualToString:@"loginText"] ||
                        [key isEqualToString:@"provinceCityDistrict"]) {
                    }else {
                        [defs removeObjectForKey:key];
                        [defs synchronize];
                    }
                }
                UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:result.resultData.errorMsg preferredStyle:UIAlertControllerStyleAlert];
                UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
                    [appInstance showLogin];
                }];
                [alertController addAction:cancelAction];
                [self presentViewController:alertController animated:YES completion:nil];
            }
        }
        [self hideHud];
    } failure:^(YTKBaseRequest *request) {
        [self showToast:@"连接服务器失败，请检查网络！"];
        [self hideHud];
    }];
}

#pragma  mark - 经纪人
- (void)postGetConsultantListApi {
    GetConsultantListApi *api = [[GetConsultantListApi alloc] initWithResourcesCode:nil searchType:nil];
    [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        GetConsultantListApi *result = (GetConsultantListApi *)request;
        if (result.isSuccess) {
            GetConsultantList *get = result.resultData;
            _getConsultantList = get;
            for (ConsultantList *list in get.consultantList) {
                [_zyDataArr addObject:list.consultantUserName];
                [_zyData addObject:list];
            }
          
        } else {
            if ([result.resultData.errorCode isEqualToString:@"YUplf0wyU5vPVssLSG"] || [result.resultData.errorCode isEqualToString:@"108E65843mYuwqb01X"]) {
                NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
                NSDictionary *dictionary = [defs dictionaryRepresentation];
                for(NSString *key in [dictionary allKeys]){
                    if ([key isEqualToString:@"DeviceToken123"] ||
                        [key isEqualToString:@"loginText"] ||
                        [key isEqualToString:@"provinceCityDistrict"]) {
                    }else {
                        [defs removeObjectForKey:key];
                        [defs synchronize];
                    }
                }
                UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:result.resultData.errorMsg preferredStyle:UIAlertControllerStyleAlert];
                UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
                    [appInstance showLogin];
                }];
                [alertController addAction:cancelAction];
                [self presentViewController:alertController animated:YES completion:nil];
            }
        }
        [self hideHud];
    } failure:^(YTKBaseRequest *request) {
        [self showToast:@"连接服务器失败，请检查网络！"];
        [self hideHud];
    }];
}

- (void)postGetUserCallListApi:(CustomerList *)list {
    [self showHudInWindow:@"正在加载中..."];
    GetUserCallListApi *api = [[GetUserCallListApi alloc] initWith];
    [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        GetUserCallListApi *result = (GetUserCallListApi *)request;
        //请求成功
        if (result.isSuccess) {
            GetUserCallList *get = result.resultData;
            if ([NSString isStringEmpty2:get.isPhoneInformation] == NO) {
                if ([get.isPhoneInformation isEqualToString:@"0"]) {
                    if ([NSString isStringEmpty2:list.mobile] == NO) {
                        [self creatinitWithGetPhone:list.mobile];
                    }
                }else {
                    UserCallMenuView *userListV = [[UserCallMenuView alloc] initWithFrame:CGRectMake(0, 0, EMM_WIDTH, EMM_HEIGHT) title:@"选择拨打号码" nameArr:get.userCallList];
                    userListV.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
                    [[UIApplication sharedApplication].keyWindow addSubview:userListV];
                    __weak UserCallMenuView *weakMenuView = userListV;
                    [userListV setTouchUserCallMenuViewBlock:^(NSString *telePhone, NSString *telePhoneType) {
                        NSLog(@"%@-%@",telePhone,telePhoneType);
                        if ([NSString isStringEmpty2:telePhone] == NO) {
                            [self postGetCallBackApi:list telePhoneString:telePhone];
                        }
                        [weakMenuView removeFromSuperview];
                    }];
                }
            }else {
                if ([NSString isStringEmpty2:list.mobile] == NO) {
                    [self creatinitWithGetPhone:list.mobile];
                }
            }
        } else {
            if ([result.resultData.errorCode isEqualToString:@"YUplf0wyU5vPVssLSG"] || [result.resultData.errorCode isEqualToString:@"108E65843mYuwqb01X"]) {
                NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
                NSDictionary *dictionary = [defs dictionaryRepresentation];
                for(NSString *key in [dictionary allKeys]){
                    if ([key isEqualToString:@"DeviceToken123"] ||
                        [key isEqualToString:@"loginText"] ||
                        [key isEqualToString:@"provinceCityDistrict"]) {
                    }else {
                        [defs removeObjectForKey:key];
                        [defs synchronize];
                    }
                }
                UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:result.resultData.errorMsg preferredStyle:UIAlertControllerStyleAlert];
                UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
                    [appInstance showLogin];
                }];
                [alertController addAction:cancelAction];
                [self presentViewController:alertController animated:YES completion:nil];
            }
        }
        [self hideHud];
    } failure:^(YTKBaseRequest *request) {
        [self showToast:@"连接服务器失败，请检查网络！"];
        [self hideHud];
    }];
}

- (void)postGetCallBackApi:(CustomerList *)list telePhoneString:(NSString *)telePhoneString {
    
    GetCallBackApi *api = [[GetCallBackApi alloc] initWithCustomerId:list.customerId caller:telePhoneString called:list.mobile terminalModel:@"0" terminalModelId:list.customerId];
    [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        GetCallBackApi *result = (GetCallBackApi *)request;
        //请求成功
        if (result.isSuccess) {
            GetCallBack *get = result.resultData;
            FollowUpViewController *fvc = [[FollowUpViewController alloc] init];
            fvc.customerId = list.customerId;
            fvc.followId = get.followId;
            [self.navigationController pushViewController:fvc animated:YES];
        } else {
            if ([result.resultData.errorCode isEqualToString:@"YUplf0wyU5vPVssLSG"] || [result.resultData.errorCode isEqualToString:@"108E65843mYuwqb01X"]) {
                NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
                NSDictionary *dictionary = [defs dictionaryRepresentation];
                for(NSString *key in [dictionary allKeys]){
                    if ([key isEqualToString:@"DeviceToken123"] ||
                        [key isEqualToString:@"loginText"] ||
                        [key isEqualToString:@"provinceCityDistrict"]) {
                    }else {
                        [defs removeObjectForKey:key];
                        [defs synchronize];
                    }
                }
                UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:result.resultData.errorMsg preferredStyle:UIAlertControllerStyleAlert];
                UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
                    [appInstance showLogin];
                }];
                [alertController addAction:cancelAction];
                [self presentViewController:alertController animated:YES completion:nil];
            }
        }
        [self hideHud];
    } failure:^(YTKBaseRequest *request) {
        [self showToast:@"连接服务器失败，请检查网络！"];
        [self hideHud];
    }];
}

@end
